package org.xg.study.boot.common.error;

import lombok.Getter;
import org.xg.study.boot.common.constant.ResponseCode;

/**
 * @author CMG
 * @version 1.0
 * @cLassName ServiceException
 * @description
 * @date 2021/8/25 17:23
 **/
public class ServiceException extends RuntimeException {
    @Getter
    private final ResponseCode responseCode;

    public ServiceException(String message) {
        super(message);
        this.responseCode = ResponseCode.FAILURE;
    }

    public ServiceException(ResponseCode responseCode) {
        super(responseCode.getRetMsg());
        this.responseCode = responseCode;
    }

    public ServiceException(ResponseCode responseCode, String msg) {
        super(msg);
        this.responseCode = responseCode;
    }

    public ServiceException(ResponseCode responseCode, Throwable cause) {
        super(cause);
        this.responseCode = responseCode;
    }

    public ServiceException(String msg, Throwable cause) {
        super(msg, cause);
        this.responseCode = ResponseCode.FAILURE;
    }

    /**
     * for better performance
     *
     * @return Throwable
     */
    @Override
    public Throwable fillInStackTrace() {
        return this;
    }

    public Throwable doFillInStackTrace() {
        return super.fillInStackTrace();
    }
}
